package com.danciyixue.boot.dcyx.controller;

import com.danciyixue.boot.dcyx.service.UnitStudyStatusService;
import lombok.RequiredArgsConstructor;
import org.springframework.web.bind.annotation.RequestMapping;
import org.springframework.web.bind.annotation.RestController;
import com.danciyixue.boot.dcyx.model.form.UnitStudyStatusForm;
import com.danciyixue.boot.dcyx.model.query.UnitStudyStatusQuery;
import com.danciyixue.boot.dcyx.model.vo.UnitStudyStatusVO;
import com.baomidou.mybatisplus.core.metadata.IPage;
import com.danciyixue.boot.common.result.PageResult;
import com.danciyixue.boot.common.result.Result;
import io.swagger.v3.oas.annotations.Parameter;
import io.swagger.v3.oas.annotations.tags.Tag;
import io.swagger.v3.oas.annotations.Operation;
import org.springframework.security.access.prepost.PreAuthorize;
import org.springframework.validation.annotation.Validated;
import org.springframework.web.bind.annotation.*;
import jakarta.validation.Valid;

/**
 * 用户单元学习状态前端控制层
 *
 * @author youlaitech
 * @since 2025-06-27 11:06
 */
@Tag(name = "用户单元学习状态接口")
@RestController
@RequestMapping("/api/v1/unit-study-status")
@RequiredArgsConstructor
public class UnitStudyStatusController  {

    private final UnitStudyStatusService unitStudyStatusService;

    @Operation(summary = "用户单元学习状态分页列表")
    @GetMapping("/page")
    @PreAuthorize("@ss.hasPerm('dcyx:unit-study-status:query')")
    public PageResult<UnitStudyStatusVO> getUnitStudyStatusPage(UnitStudyStatusQuery queryParams ) {
        IPage<UnitStudyStatusVO> result = unitStudyStatusService.getUnitStudyStatusPage(queryParams);
        return PageResult.success(result);
    }

    @Operation(summary = "新增用户单元学习状态")
    @PostMapping
    @PreAuthorize("@ss.hasPerm('dcyx:unit-study-status:add')")
    public Result<Void> saveUnitStudyStatus(@RequestBody @Valid UnitStudyStatusForm formData ) {
        boolean result = unitStudyStatusService.saveUnitStudyStatus(formData);
        return Result.judge(result);
    }

    @Operation(summary = "获取用户单元学习状态表单数据")
    @GetMapping("/{id}/form")
    @PreAuthorize("@ss.hasPerm('dcyx:unit-study-status:edit')")
    public Result<UnitStudyStatusForm> getUnitStudyStatusForm(
        @Parameter(description = "用户单元学习状态ID") @PathVariable Long id
    ) {
        UnitStudyStatusForm formData = unitStudyStatusService.getUnitStudyStatusFormData(id);
        return Result.success(formData);
    }

    @Operation(summary = "修改用户单元学习状态")
    @PutMapping(value = "/{id}")
    @PreAuthorize("@ss.hasPerm('dcyx:unit-study-status:edit')")
    public Result<Void> updateUnitStudyStatus(
            @Parameter(description = "用户单元学习状态ID") @PathVariable Long id,
            @RequestBody @Validated UnitStudyStatusForm formData
    ) {
        boolean result = unitStudyStatusService.updateUnitStudyStatus(id, formData);
        return Result.judge(result);
    }

    @Operation(summary = "删除用户单元学习状态")
    @DeleteMapping("/{ids}")
    @PreAuthorize("@ss.hasPerm('dcyx:unit-study-status:delete')")
    public Result<Void> deleteUnitStudyStatuss(
        @Parameter(description = "用户单元学习状态ID，多个以英文逗号(,)分割") @PathVariable String ids
    ) {
        boolean result = unitStudyStatusService.deleteUnitStudyStatuss(ids);
        return Result.judge(result);
    }
}
